package org.qloudgen.borg.thread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.qloudgen.borg.CommonValues;
import org.qloudgen.borg.messaging.message.TaskMessage;
import org.qloudgen.borg.metadb.DefaultImpl;
import org.qloudgen.borg.task.TaskExecutor;

public class Worker extends Thread{

	private TaskMessage task;
		
	static Log log = LogFactory.getLog(Worker.class);
	
	public Worker(TaskMessage task){
		this.setTask(task);
	}
	
	@Override
	public void run(){
		
		// update task status
		DefaultImpl.updateTaskStatus(task, CommonValues.TASK_STATUS_RUNNING);
				
		// execute task
		new TaskExecutor(task).start();	
		
	}

	/**
	 * @return the task
	 */
	public TaskMessage getTask() {
		return task;
	}

	/**
	 * @param task the task to set
	 */
	public void setTask(TaskMessage task) {
		this.task = task;
	}
	
}
